<?php 

function show_youtube($text, $VID_WID = 590, $VID_HEI = 390){
	for ($k=0; $k<9; $k++){
		$text .= ' ';
		$find = 'youtube.com/watch?v=';
		$pos = strpos($text, $find);
		if ($pos === false)	{
			break;
		}
		$len = strlen($text);
		for ($i=$pos; $i>=0; $i--){
			if (substr($text, $i, 6) == 'http:/'){
				$pos1 = $i;
				break;
			}
		}
		for ($i=$pos; $i<$len; $i++){
			if (in_array($text[$i], array('&', ' ', "\r", "\n", ',', "\t"))){
				$pos2 = $i;
				break;
			}
		}
		$link1 = substr($text, $pos1, $pos2 - $pos1);
		$link2 = str_replace('/watch?v=', '/v/', $link1);

		$embed =	'<object width="' . $VID_WID . '" height="' . $VID_HEI . '">'.
					'<param name="movie" value="' . $link2 . '"></param>'.
					'<param name="allowFullScreen" value="true"></param>'.
					'<param name="allowscriptaccess" value="always"></param>'.
					'<embed src="' . $link2 . '" type="application/x-shockwave-flash" '.
					'allowscriptaccess="always" allowfullscreen="true" '.
					'width="' . $VID_WID . '" height="' . $VID_HEI . '"></embed></object>';

		$text = str_replace($link1, $embed, $text);
	}
	return $embed;
}

function get_thumbnail($url, $width=80){
    parse_str(parse_url($url, PHP_URL_QUERY ), $array);
	$vid_id = $array['v']; 
	return "<img src='http://img.youtube.com/vi/$vid_id/default.jpg' style='width:".$width."px !important'>";
}
?>